//
//  HomeInformationVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/6/8.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "HomeInformationVC.h"
#import "InformationCell.h"
#import "Home_TypeView.h"
#import "InformationTopView.h"
#import "PredictVC.h"
#import "LabCell.h"
#import "MJRefresh.h"
#import "InformationVM.h"
#import "InformationLeftImageCell.h"
#import "InformationImageCell.h"
#import "LotteryVC.h"
#import "OpenLotteryRecordVC.h"
#import "AdvertisingView.h"
#import "ImageTableViewCell.h"
#import "InformationVC.h"
#import "InfoTypeView.h"
#import "NewsMasterCell.h"
#import "PlanPeopleVC.h"
#import "MasterListVC.h"
#import "PlanVC.h"
#import "HomePageVM.h"


#import "AdvertisingTableViewCell.h"

#import "TGInformationViewController.h"

@interface HomeInformationVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
//@property (nonatomic ,strong) UIButton   *navTitleBtn;
@property (nonatomic ,strong) UITableView  *tableView;
///六合彩
@property (nonatomic ,strong) LotteryVC     *lotteryVC;
///新闻栏目列表
@property (nonatomic ,strong) NSMutableArray *newTypeArr;
@property (nonatomic ,strong) NSMutableArray *downTypeArr;
@property (nonatomic ,strong) Home_TypeView *home_TypeView;
@property (nonatomic ,strong) InformationTopView *topView;
@property (nonatomic ,assign) NSInteger   selectLottery;
@property (nonatomic ,strong) NSArray       *advertisingArr;

@property (nonatomic ,strong) InfoTypeView  *infoTypeView;

@property (nonatomic ,strong) UIView        *infoTopView;
@property (nonatomic ,strong) AdvertisingView        *oneAdvertisingView;
@property (nonatomic ,strong) AdvertisingView        *twoAdvertisingView;

@property (nonatomic ,strong) AdvertisingView        *threeAdvertisingView;


//cell上
@property (nonatomic ,strong) AdvertisingModel        *advertisingModel;

@property (nonatomic ,strong) UICollectionView  *collectionView;
@property (nonatomic ,strong) NSArray           *peopleArr;



@property (nonatomic ,strong) NSMutableArray *arr1;
@property (nonatomic ,strong) NSMutableArray *arr2;
@property (nonatomic ,strong) NSMutableArray *arr3;


//新增顶部彩种分类（包含最新资讯、比[InformationVM manage].lotteryTypeArr多一个最新资讯）
@property (nonatomic ,strong) NSMutableArray *topLotteryArr;





@end

@implementation HomeInformationVC{
    NSInteger   page;
    BOOL        isData;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.arr1 = [NSMutableArray array];
    self.arr2 = [NSMutableArray array];
    self.arr3 = [NSMutableArray array];
    
    self.topLotteryArr = [NSMutableArray array];


    [self setRightItem];
    
    page=1;
    
}

-(void)setRightItem{
    
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(onclickNav)];
    self.navigationItem.rightBarButtonItem=rightItem;
    
}

- (void)backClick{
    if (isData) {
        [super backClick];
    }else{
        [self.navigationController popToViewController:self.saveViewController animated:YES];
    }
    [self.topView cancleTimer];
    [self.lotteryVC cancleTimer];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getLotteryType];
}

#pragma mark -- 获取彩票分类
- (void)getLotteryType{
    WS(weakSelf);
    [[InformationVM manage] getNewsLotteryTypeListWithSuccess:^(id returnValue) {

        if (weakSelf.lType.length>0) {
            
            NewsLottryTypeModel *model=[[NewsLottryTypeModel alloc] init];
            model.LType = @"0";
            model.Id = @"0";
            model.LTypeName = @"最新资讯";
            [self.topLotteryArr removeAllObjects];
            [self.topLotteryArr addObject:model];
            [self.topLotteryArr addObjectsFromArray:[InformationVM manage].lotteryTypeArr];
           
            for (int i=0; i<self.topLotteryArr.count; i++) {
                
                NewsLottryTypeModel *model=[InformationVM manage].lotteryTypeArr[i];
                
                if ([model.LType integerValue]==[weakSelf.lType integerValue]) {
                    _selectLottery=i+1;
                    weakSelf.lType=nil;
                    break;
                }
            }
        }
        weakSelf.navigationItem.titleView=[self navTitleBtn];
        NewsLottryTypeModel *model=self.topLotteryArr[_selectLottery];
        if ([model.Id intValue]==5) {
            weakSelf.lotteryVC.view.hidden=NO;
            weakSelf.lotteryVC.typeModel=model;
        }else if ([model.Id integerValue] == 0){
            
            TGInformationViewController *vc = [[TGInformationViewController alloc] init];
            vc.saveViewController = self;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            weakSelf.lotteryVC.view.hidden=YES;
            [weakSelf getNewsList:model];
            [weakSelf getLotteryInfo:model];
        }
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}

- (void)setLotteryWithType:(NSInteger)type andIndex:(NSInteger)index{
    isData=YES;
    self.selectLottery=type;
//    self.navigationItem.titleView=self.navTitleBtn;
    self.title=@"6彩";
    self.lotteryVC.view.hidden=YES;
    NewsLottryTypeModel *model=self.topLotteryArr[self.selectLottery];
    [self getNewsList:model];
    [self getLotteryInfo:model];
}

#pragma mark -- 获取推荐高手
- (void)getRecommendMaster{
    WS(weakSelf);
    [[InformationVM manage] getRecommendMasterListWithLType:self.infoTypeView.lType Success:^(id returnValue) {
        weakSelf.peopleArr=returnValue;
        [weakSelf.collectionView reloadData];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}

#pragma mark -- 获取新闻栏目列表
- (void)getNewsList:(NewsLottryTypeModel *)model{
    WS(weakSelf);
    self.infoTypeView.lType=model.LType;
    self.infoTypeView.name=model.LTypeName;
    [[InformationVM manage] getNewsTypeListWithId:model.Id Success:^(id returnValue) {
        [weakSelf createNewsType:returnValue];
        weakSelf.newTypeArr=returnValue;
        [weakSelf.infoTypeView setDataArr:returnValue];
        [weakSelf.tableView reloadData];
        [weakSelf.tableView.header beginRefreshing];
        [weakSelf getNews];
        if (weakSelf.advertisingArr==nil) {
            [weakSelf getAdvertising];
        }
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
    [self getRecommendMaster];
}
#pragma mark -- 新闻分类
- (void)createNewsType:(NSArray *)arr{
    [self.downTypeArr removeAllObjects];
    for (int i=0; i<arr.count; i++) {
        NewsTypeModel *model=arr[i];
        model.index=i;
        if (![model.TypeName isEqualToString:@"玄机图库"]) {
            [self.downTypeArr addObject:model];
        }
    }
}

#pragma mark -- 获取彩种开奖信息
- (void)getLotteryInfo:(NewsLottryTypeModel *)model{
    WS(weakSelf);
    [[HomePageVM manage] getLotteryInfoWithId:model.LType Success:^(id returnValue) {
        [weakSelf.topView setLotteryModel:returnValue];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}
#pragma mark-- 获取新闻列表
- (void)getNews{
    for (int i=0; i<self.downTypeArr.count; i++) {
        [self getNewsContentList:self.downTypeArr[i]];
    }
}

- (void)getNewsContentList:(NewsTypeModel *)model{
    [SVProgressHUD show];
    WS(weakSelf);
    if (model.ShowType==1) {
        [[InformationVM manage] getNewsListWithId:model.Id Success:^(id returnValue) {
            model.newsArr=returnValue;
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.header endRefreshing];
        } andFail:^(NSString *errorMessage, NSError *error) {
            [weakSelf.tableView.header endRefreshing];
        }];
    }
}

#pragma mark -- 获取广告
- (void)getAdvertising{
    WS(weakSelf);
    if ([BaseVM manage].city.length>0) {
        [[InformationVM manage] getAdvertWithLocation:@"0" andType:12 Success:^(id returnValue) {
            weakSelf.advertisingArr=returnValue;
            [weakSelf addAdvertising];
        } andFail:^(NSString *errorMessage, NSError *error) {
            
        }];
    }
}

- (void)addAdvertising{

    [self.arr1 removeAllObjects];
    [self.arr2 removeAllObjects];
    [self.arr3 removeAllObjects];

    for (AdvertisingModel *model in self.advertisingArr) {
        if (model.Layer==1) {
            [self.arr1 addObject:model];
//            self.oneAdvertisingView.dataArr=[NSMutableArray arrayWithObject:model];
        }else if (model.Layer==2){
            [self.arr2 addObject:model];
//            self.twoAdvertisingView.dataArr=[NSMutableArray arrayWithObject:model];
        }else if(model.Layer == 3){
            [self.arr3 addObject:model];
//            //MARK:
//            self.advertisingModel = model;
        }
    }
//    if (self.arr3.count>0) {
//        self.advertisingModel = self.arr3.lastObject;
//    }
    self.oneAdvertisingView.dataArr = self.arr1;
    self.twoAdvertisingView.dataArr = self.arr2;
//    self.threeAdvertisingView.dataArr = self.arr3;


    //MARK:
    
    _infoTopView.frame=CGRectMake(0, 0, SCREEN_WIDTH, real_size(326+40*self.arr1.count+40*self.arr2.count));
    
   
//    self.threeAdvertisingView.changeHeight(self.arr3.count*40);

   
//    if (!self.isHiddenAd1&&!self.isHiddenAd2) {
//        _infoTopView.frame=CGRectMake(0, 0, SCREEN_WIDTH, real_size(406));
//    }else if (self.isHiddenAd1&&self.isHiddenAd2){
//
//        _infoTopView.frame=CGRectMake(0, 0, SCREEN_WIDTH, real_size(326));
//
//    }else{
//        _infoTopView.frame=CGRectMake(0, 0, SCREEN_WIDTH, real_size(366));
//
//    }
    _tableView.tableHeaderView=[self infoTopView];
    
     [self.tableView reloadData];
    
}

#pragma mark -- 点击更多新闻资讯
- (void)onclickMore:(UIButton *)sender{
    InformationVC *vc=[[InformationVC alloc]init];
    NewsTypeModel *model=self.downTypeArr[sender.tag];
    vc.lType=model.LType;
    vc.index=model.index;
    if (self.topLotteryArr.count>self.selectLottery) {
        NewsLottryTypeModel *model=self.topLotteryArr[self.selectLottery];
        vc.title=model.LTypeName;
    }
    vc.saveViewController=self;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark -- 点击顶部彩种分类
- (void)onclickType:(UIButton *)sender{
    if (self.home_TypeView) {
        [self.home_TypeView remove];
        self.home_TypeView=nil;
        return;
    }
    isData=NO;
    WS(weakSelf);
    self.home_TypeView=[[Home_TypeView alloc]init];
   
    [self.home_TypeView setNOTitleArr:self.topLotteryArr andIndex:self.selectLottery andSelectBlock:^(NSInteger row) {
        if (weakSelf.selectLottery!=row) {
            weakSelf.selectLottery=row;
            weakSelf.home_TypeView=nil;
//            weakSelf.lType=nil;
            [weakSelf getLotteryType];
        }
    }];
    [self.view addSubview:self.home_TypeView];
    [self.home_TypeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(weakSelf.view);
    }];
}
#pragma mark - 点击了广告
-(void)onclickLab:(UITapGestureRecognizer *)tap{
    
    if ([self.advertisingModel.Title containsString:@"】"]) {
        UIPasteboard *copy = [UIPasteboard generalPasteboard];
        NSRange startRange = [self.advertisingModel.Title rangeOfString:@"【"];
        NSRange endRange = [self.advertisingModel.Title rangeOfString:@"】"];
        NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
        NSString *result = [self.advertisingModel.Title substringWithRange:range];
        
        [copy setString:result];
        
        [SVProgressHUD showSuccessWithStatus:@"复制成功"];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [SVProgressHUD dismiss];
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString: @"weixin://"]];
        });
    }else{
        if (self.advertisingModel.TransferUrl.length<1) {return;}
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:self.advertisingModel.TransferUrl]];
    }
    
}
#pragma mark -- UITableViewDelegate ,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.downTypeArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NewsTypeModel *model=self.downTypeArr[section];
    if (section == 0) {
        return model.newsArr.count+self.arr3.count;
    }
    
   
    return model.newsArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewsTypeModel *typeModel=self.downTypeArr[indexPath.section];
    NSArray *arr=typeModel.newsArr;
    if (indexPath.section == 0 && indexPath.row>=arr.count) {
        
//        InformationCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationCell_AD" forIndexPath:indexPath];
//        [cell setAdModel:self.arr3[indexPath.row -arr.count]];
//        return cell;
        
        AdvertisingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AdvertisingTableViewCell" forIndexPath:indexPath];
        
        [cell setModel:self.arr3[indexPath.row -arr.count]];
        
        return cell;
    }
    
    NewsModel *model=arr[indexPath.row];
    if (model.ThumbStyle==0) {
        
        InformationCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationCell" forIndexPath:indexPath];
        [cell setModel:model];
        return cell;
    }else if (model.ThumbStyle==1){
        InformationLeftImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationLeftImageCell" forIndexPath:indexPath];
        [cell setModel:model];
        return cell;
    }else{
        InformationImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationImageCell" forIndexPath:indexPath];
        [cell setModel:model];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NewsTypeModel *typeModel=self.downTypeArr[indexPath.section];
    NSArray *arr=typeModel.newsArr;
  
    if (indexPath.section == 0 &&indexPath.row>=arr.count) {
        AdvertisingModel *adModel = self.arr3[indexPath.row-arr.count];
        
        if ([adModel.Title containsString:@"】"]) {
            UIPasteboard *copy = [UIPasteboard generalPasteboard];
            NSRange startRange = [adModel.Title rangeOfString:@"【"];
            NSRange endRange = [adModel.Title rangeOfString:@"】"];
            NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
            NSString *result = [adModel.Title substringWithRange:range];
            
            [copy setString:result];
            
            [SVProgressHUD showSuccessWithStatus:@"复制成功"];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [SVProgressHUD dismiss];
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString: @"weixin://"]];
                
            });
            
        }else{
            if (adModel.TransferUrl.length<1) {return;}
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:adModel.TransferUrl]];
        }
        
        return;
    }
    
    
    NewsModel *model=typeModel.newsArr[indexPath.row];
    
    model.TypeId=typeModel.Id;
    PredictVC   *vc=[[PredictVC alloc]init];
    NewsLottryTypeModel *newsModel=self.topLotteryArr[self.selectLottery];
    vc.title=[NSString stringWithFormat:@"%@.%@",newsModel.LTypeName,typeModel.TypeName];
    vc.model=model;
    vc.saveViewController=self;
    [self.navigationController pushViewController:vc animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    NewsTypeModel *model=self.downTypeArr[section];
    if (model.newsArr.count>0) {
        return 40;
    }
    return 0;
}
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//
//    if (self.arr3.count>0&& section ==0) {
//        return 40 *self.arr3.count;
//    }
//    return 0;
//}

//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//
//    UIView *view=[[UIView alloc] init];
//    view.backgroundColor=[UIColor whiteColor];
//
//    [view addSubview:self.threeAdvertisingView];
//
//    [self.threeAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.top.equalTo(view);
//        make.height.mas_equalTo(self.arr3.count * 40);
//    }];
//
//    return view;
//
//}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    NewsTypeModel *typeModel=self.downTypeArr[section];
    //    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    UIView *view=[[UIView alloc] init];
    
    view.backgroundColor=[UIColor whiteColor];
    UIView *line=[[UIView alloc]init];
    line.backgroundColor=DEFAULTBGCOLOR;
    [view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(view);
        make.height.mas_equalTo(@.7);
    }];
    
    QXLable *lab=[[QXLable alloc] initWithBFount:15];
    lab.text=typeModel.TypeName;
    lab.textColor=NAVCOLOR;
    [view addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).with.offset(11);
        make.centerY.equalTo(view);
    }];
    
    
    UIButton *btnMore=[[UIButton alloc]init];
    [btnMore setTitle:@"更多" forState:UIControlStateNormal];
    [btnMore.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btnMore setTitleColor:DEFAULTTEXTGDARKRAYCOLOR forState:UIControlStateNormal];
    btnMore.tag=section;
    [btnMore addTarget:self action:@selector(onclickMore:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btnMore];
    [btnMore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(view);
        make.width.mas_equalTo(@80);
    }];
    
//    if (section == 1) {
//        view.frame = CGRectMake(0, 0, SCREEN_WIDTH, 100);
//        UIView *garyView = [[UIView alloc] init];
//        garyView.backgroundColor = DEFAULTBGCOLOR;
//        [view addSubview:garyView];
//        [garyView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.equalTo(view);
//            make.height.mas_equalTo(@10);
//            make.top.equalTo(line.mas_bottom);
//        }];
    
//        [view addSubview:self.threeAdvertisingView];
//        [self.threeAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.equalTo(view);
//            make.top.equalTo(garyView.mas_bottom);
//            make.height.mas_equalTo(40);
//        }];

//        UIView *line=[[UIView alloc]init];
//        line.backgroundColor=DEFAULTBGCOLOR;
//        [view addSubview:line];
//        [line mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.bottom.equalTo(view);
//            make.height.mas_equalTo(@.7);
//        }];
//
//    }
    
    return view;
}

#pragma mark - UICollectionViewDataSourse
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.peopleArr.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NewsMasterCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"NewsMasterCell" forIndexPath:indexPath];
    cell.model=self.peopleArr[indexPath.row];
    return cell;
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    ExpertsModel *eModel=self.peopleArr[indexPath.row];
    PlanPeopleVC *vc=[[PlanPeopleVC alloc]init];
    LotteryTypeModel *lotteryModel=[[LotteryTypeModel alloc]init];
    lotteryModel.lType=eModel.lType;
    vc.lotteryModel=lotteryModel;
    vc.model=eModel;
    vc.playName=eModel.PlayName;
    if (self.topLotteryArr.count>self.selectLottery) {
        NewsLottryTypeModel *model=self.topLotteryArr[self.selectLottery];
        vc.title=[NSString stringWithFormat:@"%@近期竞彩",model.LTypeName];
    }
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark -- 懒加载
- (UITableView *)tableView{
    if (!_tableView) {
        WS(weakSelf);
        _tableView=[[UITableView alloc]init];
        _tableView.dataSource=self;
        _tableView.delegate=self;
        _tableView.backgroundColor=DEFAULTBGCOLOR;
        [_tableView registerClass:[InformationCell class] forCellReuseIdentifier:@"InformationCell"];
//        [_tableView registerClass:[InformationCell class] forCellReuseIdentifier:@"InformationCell_AD"];

        [_tableView registerClass:[InformationLeftImageCell class] forCellReuseIdentifier:@"InformationLeftImageCell"];
        [_tableView registerClass:[InformationImageCell class] forCellReuseIdentifier:@"InformationImageCell"];
        
        [_tableView registerClass:[ImageTableViewCell class] forCellReuseIdentifier:@"ImageTableViewCell"];
        
        [_tableView registerClass:[AdvertisingTableViewCell class] forCellReuseIdentifier:@"AdvertisingTableViewCell"];
        _tableView.tableHeaderView=[self infoTopView];
        _tableView.estimatedRowHeight=150.0f;
        _tableView.rowHeight=UITableViewAutomaticDimension;
        
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
        
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(weakSelf.view);
        }];
        
    }
    return _tableView;
}



- (UIView *)infoTopView{
    if (!_infoTopView) {
        _infoTopView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, real_size(325))];
        [_infoTopView addSubview:self.topView];
        [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(_infoTopView);
            make.height.mas_equalTo(@(real_size(80)));
        }];
        
        [_infoTopView addSubview:self.infoTypeView];
        [self.infoTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_infoTopView);
            make.top.equalTo(self.topView.mas_bottom).with.offset(.7);
            make.height.mas_equalTo(@(real_size(100)));
        }];
        
        [_infoTopView addSubview:self.oneAdvertisingView];
        [self.oneAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_infoTopView);
            make.top.equalTo(self.infoTypeView.mas_bottom);
            make.height.mas_equalTo(@0);
        }];
        
        
        [_infoTopView addSubview:self.collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_infoTopView);
            make.height.mas_equalTo(@(real_size(140)));
            make.top.equalTo(self.oneAdvertisingView.mas_bottom).with.offset(real_size(5));
        }];
        
        [_infoTopView addSubview:self.twoAdvertisingView];
        [self.twoAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_infoTopView);
            make.top.equalTo(self.collectionView.mas_bottom);
            make.height.mas_equalTo(@0);
        }];
        
    }
    return _infoTopView;
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        [layout setItemSize:CGSizeMake(real_size(100), real_size(140))];
        [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        layout.minimumInteritemSpacing = 0.0;
        layout.minimumLineSpacing = 0.0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor=[UIColor whiteColor];
        [_collectionView registerClass:[NewsMasterCell class] forCellWithReuseIdentifier:@"NewsMasterCell"];
        
    }
    return _collectionView;
}

- (InfoTypeView *)infoTypeView{
    if (!_infoTypeView) {
        _infoTypeView=[[InfoTypeView alloc]init];
    }
    return _infoTypeView;
}

- (InformationTopView *)topView{
    if (!_topView) {
        _topView=[[InformationTopView alloc]initWithModel:[[Home_LotteryModel alloc]init]];
    }
    return _topView;
}

- (NSMutableArray *)newTypeArr{
    if (!_newTypeArr) {
        _newTypeArr=[[NSMutableArray alloc]init];
    }
    return _newTypeArr;
}

- (NSMutableArray *)downTypeArr{
    if (!_downTypeArr) {
        _downTypeArr=[[NSMutableArray alloc]init];
    }
    return _downTypeArr;
}

- (UIButton *)navTitleBtn{
    NSString *title=@"";
    if (self.topLotteryArr.count>self.selectLottery) {
        NewsLottryTypeModel *model=self.topLotteryArr[self.selectLottery];
        title=model.LTypeName;
    }
    
    CGFloat width=[TGTools boundingRectWithString:title withWidth:300 anfont:[UIFont boldSystemFontOfSize:19]];
    
    UIButton *_navTitleBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, width+30, 30)];
    [_navTitleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _navTitleBtn.titleLabel.font=[UIFont boldSystemFontOfSize:19];
    [_navTitleBtn setTitle:title forState:UIControlStateNormal];
    [_navTitleBtn setImage:[UIImage imageNamed:@"white_angle"] forState:UIControlStateNormal];
    [_navTitleBtn verticalImageAndTitle:width andImage:[UIImage imageNamed:@"white_angle"]];
    _navTitleBtn.layer.masksToBounds=YES;
    _navTitleBtn.layer.cornerRadius=2;
    _navTitleBtn.layer.borderColor=[UIColor whiteColor].CGColor;
    _navTitleBtn.layer.borderWidth=1;
    [_navTitleBtn addTarget:self action:@selector(onclickType:) forControlEvents:UIControlEventTouchUpInside];
    return _navTitleBtn;
}


- (AdvertisingView *)oneAdvertisingView{
    if (!_oneAdvertisingView) {
        WS(weakSelf);
        _oneAdvertisingView =[[AdvertisingView alloc]init];
        self.oneAdvertisingView.changeHeight = ^(float height) {
            [weakSelf.oneAdvertisingView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@(height));
            }];
        };
    }
    return _oneAdvertisingView;
}
- (AdvertisingView *)threeAdvertisingView{
    if (!_threeAdvertisingView) {
        WS(weakSelf);
        _threeAdvertisingView =[[AdvertisingView alloc]init];
        self.threeAdvertisingView.changeHeight = ^(float height) {
            [weakSelf.threeAdvertisingView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@(height));
            }];
        };
    }
    return _threeAdvertisingView;
}

- (AdvertisingView *)twoAdvertisingView{
    if (!_twoAdvertisingView) {
        WS(weakSelf);
        _twoAdvertisingView =[[AdvertisingView alloc]init];
        self.twoAdvertisingView.changeHeight = ^(float height) {
            [weakSelf.twoAdvertisingView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@(height));
            }];
        };
        
    }
    return _twoAdvertisingView;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (LotteryVC *)lotteryVC{
    if (!_lotteryVC) {
        WS(weakSelf);
        [self.tableView reloadData];
        _lotteryVC=[[LotteryVC alloc]init];
        _lotteryVC.selectNav = ^(LotteryNavModel *model) {
            if (model.Type==1) {
                if ([model.Name isEqualToString:@"高手计划"]) {
                    MasterListVC *vc=[[MasterListVC alloc]init];
                    vc.lType=model.Id;
                    vc.strTitle=@"6彩";
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                    
                }else if ([model.Name isEqualToString:@"官方计划"]){
                    PlanVC *vc=[[PlanVC alloc]init];
                    LotteryTypeModel *typeModel=[[LotteryTypeModel alloc]init];
                    typeModel.lType=model.Id;
                    typeModel.Name=@"6彩";
                    typeModel.Id=model.Id;
                    vc.lotteryModel=typeModel;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }else{
                    OpenLotteryRecordVC *vc =[[OpenLotteryRecordVC alloc]init];
                    vc.lType=model.Id;
                    vc.title=[NSString stringWithFormat:@"6彩开奖记录"];
                    vc.lotteryType=LotteryNumTypeLottery;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }
            }else if (model.Type==2){
                InformationVC *vc=[[InformationVC alloc]init];
                vc.saveViewController=weakSelf;
                if (self.topLotteryArr.count>weakSelf.selectLottery) {
                    NewsLottryTypeModel *model=weakSelf.topLotteryArr[weakSelf.selectLottery];
                    vc.title=model.LTypeName;
                }
                
                [vc setLotteryWithType:weakSelf.selectLottery-1 andIndex:model.index];
                [weakSelf.navigationController pushViewController:vc animated:YES];
            }else if (model.Type==3){
                PublicWebVC *vc=[[PublicWebVC alloc]init];
                vc.url=model.Url;
                vc.title=@"六合彩-开奖时间";
                [weakSelf.navigationController pushViewController:vc animated:YES];
            }
        };
        _lotteryVC.selectType = ^(NewsTypeModel *model) {
            InformationVC *vc=[[InformationVC alloc]init];
            vc.saveViewController=weakSelf;
            if (self.topLotteryArr.count>weakSelf.selectLottery) {
                NewsLottryTypeModel *model=weakSelf.topLotteryArr[weakSelf.selectLottery];
                vc.title=model.LTypeName;
            }
            [vc setLotteryWithType:weakSelf.selectLottery-1 andIndex:model.index];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        };
        [self.view addSubview:_lotteryVC.view];
        [_lotteryVC.view setFrame:self.view.bounds];
        _lotteryVC.view.hidden=YES;
        [self addChildViewController:_lotteryVC];
    }
    return _lotteryVC;
}


@end
